package com.qf.testtx;

import com.qf.bean.Zhanghu;
import com.qf.service.ZhanghuService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

/**
 * 2019/11/15
 * Administrator
 * spring_anno_aop_1113
 * 面向对象面向君  不负代码不负卿
 */
public class TestB {

    private ZhanghuService zhanghuService;

    public void setZhanghuService(ZhanghuService zhanghuService) {
        this.zhanghuService = zhanghuService;
    }

    //线程A  读取数据
     class  A extends  Thread{
             @Override
             public void run()  {
                 System.out.println("A线程开始执行");
                 List list = zhanghuService.findb();
                 System.out.println("before="+list.get(0));
                 System.out.println("after="+list.get(1));
             }
     }

    //线程B  修改数据
    class  B extends  Thread{
        @Override
        public void run() {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("B线程开始执行");
             zhanghuService.updateb();

        }
    }


    public static void main(String[] args) {
        ApplicationContext app =
                new ClassPathXmlApplicationContext("spring-TX.xml");
        TestB t2 = (TestB) app.getBean("t2");
        A a = t2.new A();
        B b=t2.new B();
        a.start();
        b.start();
    }


}
